home *** CD-ROM | disk | FTP | other *** search
/ Almathera Ten Pack 3: CDPD 3 / Almathera Ten on Ten - Disc 3: CDPD3.iso / fish / 726-750 / 745 / arexxbox / test / test.c < prev    next >
C/C++ Source or Header  |  1995-03-18  |  2KB  |  127 lines

  1. /*
  2.  * Auto: rx "say 'compiling <path><file>'"
  3.  * Auto: make test
  4.  * Buto: rx "address 'rexx_ced' 'change current directory' '<path>'"
  5.  *
  6.  */
  7.  
  8. #include "test.h"
  9. #include "rx_test.h"
  10.  
  11.  
  12. extern struct Library *SysBase, *DOSBase;
  13. struct Library *IconBase = NULL;
  14. struct Library *RexxSysBase = NULL;
  15. struct RexxHost *myhost = NULL;
  16.  
  17. struct DiskObject *program_icon = NULL;
  18. char **ttypes = NULL;
  19.  
  20. char *portname = NULL;
  21.  
  22.  
  23. /* Wenn ich die folgenden beiden Funktionen aus der amiga.lib
  24.  * importiere, dann muß ich anscheinend auch die commodities.lib
  25.  * öffnen. Der Grund ist mir schleierhaft, deshalb nehme ich
  26.  * lieber meine eigenen Routinen.
  27.  */
  28.  
  29. void argArrayDone( void )
  30. {
  31.     if( program_icon )
  32.         FreeDiskObject( program_icon );
  33. }
  34.  
  35. char **argArrayInit( LONG argc, char **argv )
  36. {
  37.     if( argc )
  38.         return argv;
  39.     
  40.     else
  41.     {
  42.         struct WBStartup *wbs = (struct WBStartup *) argv;
  43.         
  44.         if( program_icon = GetDiskObject((char *) wbs->sm_ArgList->wa_Name) )
  45.             return( (char **) program_icon->do_ToolTypes );
  46.     }
  47.     
  48.     return NULL;
  49. }
  50.  
  51.  
  52. void closedown( void )
  53. {
  54.     argArrayDone();
  55.     if( myhost ) CloseDownARexxHost( myhost );
  56.     if( IconBase ) CloseLibrary( IconBase );
  57.     if( RexxSysBase ) CloseLibrary( RexxSysBase );
  58. }
  59.  
  60.  
  61. void init( int argc, char *argv[] )
  62. {
  63.     if( !(RexxSysBase = OpenLibrary( "rexxsyslib.library", 35 )) )
  64.         exit( 20 );
  65.     
  66.     if( !(IconBase = OpenLibrary( "icon.library", 37 )) )
  67.         exit( 20 );
  68.     
  69.     if( ttypes = argArrayInit( argc, (char **) argv ) )
  70.     {
  71.         portname = FindToolType( (UBYTE **) ttypes, "PORTNAME" );
  72.     }
  73. }
  74.  
  75.  
  76. /* Hauptprogramm */
  77.  
  78. int main( int argc, char *argv[] )
  79. {
  80.     BPTR fh;
  81.  
  82.     /* Initialisieren */
  83.     
  84.     atexit( closedown );
  85.     init( argc, argv );
  86.     
  87.     if( !(myhost = SetupARexxHost(portname)) )
  88.     {
  89.         printf( "No Host\n" );
  90.         return( 20 );
  91.     }
  92.     
  93.     /* Erst eine CommandShell... */
  94.     
  95.     if( fh = Open( "CON:////CommandShell/AUTO", MODE_NEWFILE ) )
  96.     {
  97.         CommandShell( myhost, fh, fh, "test> " );
  98.         Close( fh );
  99.     }
  100.     else
  101.         printf( "No Console\n" );
  102.     
  103.     /* ...und dann 'richtiger' ARexx-Betrieb */
  104.     
  105.     printf( "Address me on Port %s!\n", myhost->portname );
  106.     printf( "Cancel me with CTRL-C\n" );
  107.     
  108.     while( 1 )
  109.     {
  110.         long s = Wait( SIGBREAKF_CTRL_C | (1L<<myhost->port->mp_SigBit) );
  111.         
  112.         if( s == SIGBREAKF_CTRL_C )
  113.         {
  114.             if( myhost->flags & ARB_HF_CMDSHELL )
  115.                 printf( "can't quit, commandshell still open!\n" );
  116.             else
  117.                 break;
  118.         }
  119.         else
  120.         {
  121.             ARexxDispatch( myhost );
  122.         }
  123.     }
  124.     
  125.     return( 0 );
  126. }
  127.